<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h1 id="targetDom">在此显示ajax请求来的数据</h1>
  <button onclick='ajax()'>发送POST请求</button>
  <script>

    function ajax(param) {
      let http = new XMLHttpRequest()
      console.log(http);

      // 利用mockjs 自己制作接口数据
      http.onreadystatechange = function () {
        if (http.readyState == 4 && http.status == 200 || 201) {
          let res = JSON.parse(http.responseText)
          console.log(http);

          console.log(res);
          document.getElementById("targetDom").innerHTML = res.name;
        }
      }
      http.open('POST', `http://localhost:3000/users`, true)
      http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http.send('name=新名字李狗蛋');
    }

  </script>
</body>

</html>